/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author aa
 */
public class bintang extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<html>\n");
      out.write("<head>\n");
      out.write("<title>Untitled Document</title>\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
      out.write("</head>\n");
      out.write("\n");
      out.write("<body bgcolor=\"#993300\">\n");
      out.write("<form action=\"halamanutama\" method=\"post\" name=\"Daftar\" id=\"Daftar\">\n");
      out.write("  <p align=\"center\">\n");
      out.write("    <marquee direction=\"left\">\n");
      out.write("    </marquee>\n");
      out.write("    <font color=\"#FFFF00\" size=\"4\" face=\"Georgia, Times New Roman, Times, serif\">Data\n");
      out.write("    anda sudah tersimpan, jumlah angka menunjukkan deret fibonaccinya;</font></p>\n");
      out.write("  <p align=\"center\">&nbsp;</p>\n");
      out.write("  <table width=\"583\" border=\"0\" align=\"center\">\n");
      out.write("    <tr>\n");
      out.write("      <td width=\"59\" height=\"24\"><font color=\"#FFFFFF\"><strong>deret fibonacinya adalah</strong></font></td>\n");
      out.write("      <td width=\"5\"><font color=\"#999999\"><strong>:</strong></font></td>\n");
      out.write("      <td><font color=\"#000000\">\n");
      out.write("        ");
 int jumlah = Integer.parseInt(request.getParameter("angka"));

      	int a = 0;
    	int x = 2;
    	int b = 1;
    	int n = 1;
    	int c;
    	int i;
    	int angka1 [] = new int [jumlah+1];
    	angka1[0]=0;
    	angka1[1]=1;
    	while(n<=jumlah-1){
    	c = a+b;
    	angka1[x++]=c;
    	a=b;
    	b=c;
    	n++;
        }
        x--;

    	for(i =jumlah-1; i>=0;i--){

    		out.print(angka1[i+1] +" ");
    	}
        out.print("0");
        out.println("");

      out.write("\n");
      out.write("    </font></td>\n");
      out.write("    </tr>\n");
      out.write("    <tr>\n");
      out.write("     <td width=\"59\" height=\"24\"><font color=\"#FFFFFF\"><strong>ini adalah deret yang ke</strong></font></td>\n");
      out.write("     <td width=\"5\"><font color=\"#999999\"><strong>:</strong></font></td>\n");
      out.write("    <td><font color=\"#000000\">\n");
      out.write("    ");

     out.println("<font size=2 face= Verdana, Arial, Helvetica, sans-serif color=#000066>"+jumlah+"</font>");

      out.write("\n");
      out.write("    </font></td>\n");
      out.write("    </tr>\n");
      out.write("\n");
      out.write("  </table>\n");
      out.write("  <p align=\"center\"><font color=\"#FFFF00\">inilah hasil angka\n");
      out.write("    !!!</font></p>\n");
      out.write("\n");
      out.write("  </form>\n");
      out.write("</body>\n");
      out.write("</html>\n");
      out.write("\n");
      out.write("\n");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
